package com.ossfk.jt808.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.ossfk.jt808.server.Jt808Server;
import com.ossfk.net.config.NetServerConfig;

@Configuration
public class Jt808ServerConfig {
	@Value("${ossfk.jt808.server.host:127.0.0.1}")
	private String host;
	@Value("${ossfk.jt808.server.port:8000}")
	private Integer port;
	@Value("${ossfk.jt808.server.keepAlive:true}")
	private boolean keepAlive;
	@Value("${ossfk.jt808.server.readerIdleTimeSeconds:60}")
	private Long readerIdleTimeSeconds;
	@Value("${ossfk.jt808.server.name:Jt808Server}")
	private String name;

	@Bean
	public NetServerConfig netServerConfig() {
		NetServerConfig config = new NetServerConfig(host,port);
		config.setKeepAlive(keepAlive);
		config.setReaderIdleTimeSeconds(readerIdleTimeSeconds);
		config.setName(name);
		return config;
	}

	@Bean
	public Jt808Server jt808Server(NetServerConfig netServerConfig) {
		Jt808Server server = new Jt808Server(netServerConfig);
		return server;
	}
}
